﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class sites_Resevertion : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnFindFlights_Click(object sender, EventArgs e)
    {
        int amount = 0;
        string from = txtStart.Text;
        string destination = txtDestination.Text;
        int maxLayovers = 1000;//So if maximum layovers is left empty the algorithm will find the cheapest route of all with a maximum of 1000 layovers
        if (from != "" && destination != "")//Vi behøver ikke tjekke for andet da det bør tjekkes inden
        {
            try
            {
                amount = Convert.ToInt16(txtSeats.Text);
            }
            catch (FormatException seatAmountFormatException)
            {
                //MessageBox.Show("Seats must be a number");
                Response.Write("Seats must be a number");
            }
            if (txtLayovers.Text != "")
            {
                try
                {
                    maxLayovers = Convert.ToInt16(txtLayovers.Text);
                }
                catch (FormatException maxLayoversFormatException)
                {
                    //MessageBox.Show("Maximum layovers must be a positive number or left empty");
                    Response.Write("Maximum layovers must be a positive number or left empty");
                }
            }
            string date = txtDate.Text;//Tjek for om det er det ønskede format
            string time = txtTime.Text + ":00";//Tjek for om det er det ønskede format
            //    if (amount > 0)
            //    {
            //        Flight_Reservation.DataLayer.Flight[] flights = wsr.FindFlights(from, destination, maxLayovers, date, time, amount);
            //        if (flights[0].FlightNo > 0)
            //        {
            //            ShowFlightsInTable(flights);
            //            double totalPrice = 0;
            //            foreach (Flight_Reservation.DataLayer.Flight flight in flights)
            //            {
            //                totalPrice += flight.Route.Price;
            //            }
            //            tbTotalPrice.Text = totalPrice.ToString();
            //            if (customerNo != 0)
            //            {
            //                btnCreateReservation.Enabled = true;
            //            }
            //        }
            //        else
            //        {
            //            MessageBox.Show("Couldn't find flights with the given requirements");
            //        }

            //    }
            //    else
            //    {
            //        MessageBox.Show("Seats must be a possitive number");
            //    }
            //}
            //else
            //{
            //    MessageBox.Show("No fields can be empty");
            //}
        }
    }
    protected void btnSearchReservation_Click(object sender, EventArgs e)
    {
        try
        {
            int reservationNo = 0;
            reservationNo = Convert.ToInt32(txtReservationNo.Text);
            if (reservationNo > 0)
            {
                //Flight_Reservation.DataLayer.Flight[] flights = wsr.FindReservationFlights(reservationNo);
                //ShowFlightsInTable(flights);
            }
            else
            {
                //MessageBox.Show("Reservation number must be a positive number");
                Response.Write("Reservation number must be a positive number");
            }
        }
        catch (FormatException reservationNoFormatException)
        {
            //MessageBox.Show("Reservation number must be a positive number");
            Response.Write("Reservation number must be a positive number");
        }
    }
}